//
//  LYSystemMessageCell.m
//  SelectCity
//
//  Created by liuyan on 2019/3/20.
//  Copyright © 2019年 liuyan. All rights reserved.
//

#import "LYSystemMessageCell.h"

@interface LYSystemMessageCell()

@property (nonatomic, strong) UIView *backView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *detailLabel;
@property (nonatomic, strong) UIView *lineview;
@property (nonatomic, strong) UILabel *otherLabel;
@property (nonatomic, strong) UIImageView *nextImage;

@end

@implementation LYSystemMessageCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initUI];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

#pragma mark - InitSubViews
- (void)initUI {
    self.backgroundColor = [UIColor clearColor];
    
    self.backView = [[UIView alloc] initWithFrame:CGRectMake(10,0, WIDTH - 20, 80)];
    self.backView.backgroundColor = COLOR_OF_WHITE;
    self.backView.layer.cornerRadius = 5;
    self.backView.layer.masksToBounds = YES;
    [self.contentView addSubview:self.backView];
    
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 13,self.backView.width - 30, 25)];
    self.titleLabel.textColor = THEMECOLOR_OF_TEXT_333333;
    self.titleLabel.font = FontBold(Font_15);
    [self.backView addSubview:self.titleLabel];
    
    self.detailLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, self.titleLabel.bottom +5,self.backView.width - 30, 20)];
    self.detailLabel.textColor = THEMECOLOR_OF_TEXT_666666;
    self.detailLabel.numberOfLines = 0;
    self.detailLabel.font = Font(Font_13);
    [self.backView addSubview:self.detailLabel];
    
    self.lineview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.backView.width, lineH)];
    self.lineview.hidden = YES;
    self.lineview.backgroundColor = THEMECOLOR_OF_TEXT_cccccc;
    [self.backView addSubview:self.lineview];
    
    self.nextImage = [[UIImageView alloc] initWithFrame:CGRectMake(self.backView.width - 18, 0, 8, 16)];
    self.nextImage.image = [UIImage imageNamed:@"jiantou_right"];
    self.nextImage.hidden = YES;
    [self.backView addSubview:self.nextImage];
    
    self.otherLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 0,self.nextImage.left - 20, 30)];
    self.otherLabel.textColor = THEMECOLOR_OF_ORANGE;
    self.otherLabel.font = Font(Font_14);
    self.otherLabel.hidden = YES;
    [self.backView addSubview:self.otherLabel];
}

#pragma mark -- Data
- (void)setModel:(LYSystemMessageModel *)model {
    self.backView.height = model.cellheight;
    self.titleLabel.text = model.name;
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:model.detail];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:LineSpacingHeight];//调整行间距
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [model.detail length])];
    self.detailLabel.attributedText = attributedString;
    self.detailLabel.height = model.textheight+3;
    if (model.other.length) {
        self.lineview.hidden = NO;
        self.nextImage.hidden = NO;
        self.otherLabel.hidden = NO;
        self.otherLabel.text = model.other;
        self.lineview.bottom = model.cellheight-31;
        self.nextImage.top = self.lineview.bottom + 6;
        self.otherLabel.top = self.lineview.bottom;
    } else {
        self.lineview.hidden = YES;
        self.nextImage.hidden = YES;
        self.otherLabel.hidden = YES;
    }
}

@end
